// compontnts/input/lt-input.js
import {formVerify} from "../../../utils/util"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    formData:{
      type:Object,
      value:{}
    },
    field:{
      type:Object,
      value:{}
    },
    betweenSign:{
      type:String,
      value:""
    },
   
  },
  lifetimes: {
    created:function(){
      
    },
    attached: function() {
      // 在组件实例进入页面节点树时执行,初始化一些操作

     
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  observers:{
    'formData':function(formData){
      if(formData[this.data.field['field']+this.data.betweenSign]){
        this.setData({value:formData[this.data.field['field']+this.data.betweenSign]})
      }else{
        this.setData({value:""})
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    errorMessage:"",
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    clear(e){
      this.change(e)
      this.blur(e)
    },
    change(e){
      //将输入框改变的值实时赋值给formData
      this.data.formData[this.data.field['field']+this.data.betweenSign]=e.detail
      //调用父级，将值传出
      this.triggerEvent("change",{field:this.data.field['field']+this.data.betweenSign,val:e.detail})
    },
    click(e){
      this.triggerEvent("click",{field:this.data.field['field']+this.data.betweenSign})
    },
    blur(e){
      this.verify()
    },
    verify(){
      return formVerify(this)
    }
  }
})
